﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GTCAS.CommonLib.Entities;
using GTCAS.DataAccess.Common;
namespace GTCAS.DataAccess
{
    public class UserDAO : ExtendDAO
    {
        public UserDAO(long id_tinhthanh)
            : base(id_tinhthanh)
        {
        }
        /// <summary>
        /// Lay thong tin nguoi dung tuong ung voi user va pass truyen vao
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public GT_USER_NAME GetByUserPass(string username, string password)
        {
            GT_USER_NAME result = null;

            BaseDAO adapter = new BaseDAO(this.ConnectionString);
            adapter.AddParameter(":username", username);
            adapter.AddParameter(":password", password);
            try
            {
                string command = "SELECT USERNAME,HOTEN,THEME,ID FROM " + this.Schema + ".GT_USER_NAME WHERE USERNAME=:username AND PASSWORD=:password ";
                var ret = adapter.GetList<GT_USER_NAME>(command, CommandType.Text, CustomConnectionState.CloseOnExit);
                result = ret.FirstOrDefault();
            }
            catch (Exception exc)
            {//Custom Error here

                throw exc;

            }
            finally { adapter.Dispose(); }
            return result;
        }
    }
}
